<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="input">

    <script>
        function debounce(fn, delay = 200) {
            let timer = 0;
            return function () {
                if (timer) clearTimeout(timer)
                timer = setTimeout(() => {
                    fn.apply(this, arguments)
                    timer = 0;
                }, delay)
            }
        }
        const input = document.querySelector('#input');
        input.addEventListener('keyup', debounce(() => {
            console.log('发起搜索');

        }), 300)

    </script>
</body>

</html>